package com.wmh.baseservice.robot.convert;

import cn.hutool.core.collection.CollUtil;
import com.wmh.baseservice.robot.entity.RobotInfo;
import com.wmh.baseservice.robot.entity.RobotTaskStatementV2;
import com.wmh.baseservice.robot.pojo.dto.robottaskadpushunit.RobotTaskAdPushUnitPushReqVO;
import com.wmh.baseservice.robot.pojo.vo.TaskStatementAppendResultReqVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * @author 谢骏
 * @date 2023/9/11 14:39
 **/
@Mapper
public interface RobotTaskStatementV2Convert {

    RobotTaskStatementV2Convert INSTANCE = Mappers.getMapper(RobotTaskStatementV2Convert.class);

    @Mappings({
            @Mapping(source = "item.pushTaskId", target = "pushTaskUnitId"),
            @Mapping(source = "item.name", target = "pushTaskUnitName"),
            @Mapping(source = "item.robotTaskId", target = "taskId"),
            @Mapping(source = "item.robotTaskName", target = "taskName"),
            @Mapping(source = "item.statementId", target = "id"),
            @Mapping(source = "robotInfo.robotNumber", target = "robotNumber"),
            @Mapping(source = "robotInfo.robotIp", target = "robotIp"),
            @Mapping(target = "createTime",ignore = true),
            @Mapping(target = "updateTime",ignore = true)
    })
    RobotTaskStatementV2 convert(RobotTaskAdPushUnitPushReqVO.Item item, Long adId, Integer taskType, RobotInfo robotInfo);


    @Mapping(source = "reqVO.statementId" , target = "id")
    RobotTaskStatementV2 convert(TaskStatementAppendResultReqVO reqVO);

    default List<RobotTaskStatementV2> convertList(RobotTaskAdPushUnitPushReqVO reqVO, RobotInfo robotInfo) {
        return CollUtil.map(reqVO.getTaskList(),
                item -> convert(item, reqVO.getAdId(), reqVO.getPushTaskType(), robotInfo),
                true);
    }
}
